/**     
* @Title: ParseTestCase.java   
* @Package me.crawler.test   
* @Description: TODO   
* @author xaoyaoyao
* @date 2019年1月13日 下午9:24:41
*/
package me.crawler.test;

import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;

import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;

import lombok.extern.slf4j.Slf4j;
import me.crawler.downloader.HttpDownloader;
import me.crawler.dto.PoetryDtos;
import me.crawler.entity.SpiderSeed;
import me.crawler.entity.SpiderTask;
import me.crawler.enumerate.RequestMethodEnum;
import me.crawler.parser.XmlParser;

/**
 * @ClassName: ParseTestCase
 * @Description: TODO
 * @author xaoyaoyao
 * @date 2019年1月13日 下午9:24:41
 * 
 */
@Slf4j
public class ParseTestCase {

	public static void main(String[] args) throws IOException {
		String domain = "gushiwen.org";
		SpiderTask task = new SpiderTask();
		task.setRequestMethod(RequestMethodEnum.GET.getMethod());
		task.setUrl("https://www.gushiwen.org/shiju/");
		String pathName = Test.class.getResource("/poetry.xml").getFile().toString();
		String template = FileUtils.readFileToString(new File(pathName), "utf-8");
		task.setDomain(domain);

		SpiderSeed seed = new SpiderSeed();
		seed.setTemplate(template);
		seed.setDomain(domain);
		seed.setName("古诗文网");
		List<SpiderSeed> seeds = Arrays.asList(seed);

		String htmlTxt = HttpDownloader.builder().task(task).build().download();
		log.debug(">>>>>>>> htmlTxt >> {}", htmlTxt);
		if (StringUtils.isNoneBlank(htmlTxt)) {
			PoetryDtos newsDtos = XmlParser.builder().htmlTxt(htmlTxt).seeds(seeds).build().parse(PoetryDtos.class);
			log.debug(">>>>>>>> newsDtos >> {}", newsDtos);
		}
	}
}
